package com.jar.exercise.设计模式.观察者模式;


import java.util.ArrayList;
import java.util.List;

/**
 * 管理所有观察的类
 */
public class Subject {
    private List<Observer> observables = new ArrayList<>();

    private int state;

    public void attach(Observer observer) {
        observables.add(observer);
    }

    public void notifyAllObservers() {
        for (Observer observable : observables) {
            observable.update();
        }
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();
    }
}
